export class InputBox {
    constructor(onAddReminder) {
        this.onAddReminder = onAddReminder;
        this.container = null;
    }

    render() {
        if (!this.container) {
            this.container = document.createElement('div');
            this.container.className = 'input-container';
            this.container.innerHTML = `
                <div class="input-group">
                    <input type="text" id="reminder-text" placeholder="输入提醒内容">
                    <input type="datetime-local" id="reminder-time">
                    <button id="add-reminder">添加提醒</button>
                </div>
            `;
            this.bindEvents();
        }
        return this.container;
    }

    bindEvents() {
        const addButton = this.container.querySelector('#add-reminder');
        addButton.addEventListener('click', () => this.handleAddReminder());
    }

    handleAddReminder() {
        const textInput = this.container.querySelector('#reminder-text');
        const timeInput = this.container.querySelector('#reminder-time');
        
        const text = textInput.value.trim();
        const time = timeInput.value;

        if (!text) {
            alert('请输入提醒内容');
            return;
        }

        if (!time) {
            alert('请选择提醒时间');
            return;
        }

        this.onAddReminder({
            text,
            time: new Date(time).toISOString()
        });

        textInput.value = '';
        timeInput.value = '';
    }
}
    